let parser = require("@babel/parser")
let _traverse = require("@babel/traverse")
const traverse = _traverse.default;

let _generator = require("@babel/generator")
const generator = _generator.default;

const code = `let val = 1 + 2`
const ast = parser.parse(code)
// console.log(ast)

traverse(ast, {
  enter(path) {  // 这个path会找到所有的node
    if (path.node.type == 'Identifier') {
      path.node.name = 'modify'
      path.stop()
    }
  }
})

const ret = generator(ast)
console.log(ret)